<template>
  <div class="index">

    <div class="center">
      <left></left>
      <div class="right">
        <top></top>
        <div class="hei10"></div>

        <div class="where" style="background: #fff; padding: 10px 30px; font-size: 14px; color: #595959;">
          当前位置：
          <router-link to="/index" style="color: #409eff;">分销后台</router-link>>
          <router-link to="/productionDelivery" style="color: #409eff;">在售商品管理</router-link>>
          <span v-if="$route.query.id">修改商品</span>

        </div>

        <div class="hei10"></div>
        <div class="addpro"  style="width: calc(100vw - 230px);">
          <div class="step" v-loading='loading'>

            <!-- <el-steps :active="2" align-center>
              <el-step title="定义基础产品信息" description="设置分类、定制生产规则"></el-step>
              <el-step title="定义销售页信息" description="对外宣传销售话术"></el-step>
              <el-step title="设置佣金及分销商可见" description="设置那些分销商可以销售，给多少佣金"></el-step>
              <el-step title="确认发布" description="上线销售发展用户"></el-step>
            </el-steps> -->


            <!-- <div class="tilte">商品信息</div>
            <div class="con">
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="xing">*</span></div>
                  <div>选择产品:</div>
                </div>
                <div>
                  <div class="basispro" v-if="semod == 1">
                    <el-select v-model="proid" filterable disabled placeholder="请选择产品">
                      <el-option v-for="(item,index) in prolists" :key="index" :label="item.name"
                        :value="item.id"></el-option>
                    </el-select>
                    <el-checkbox style="margin-left: 20px;" v-if="this.shop_id == 50481 || this.shop_id == 304676"
                      v-model="isxn">引流商品</el-checkbox>

                  </div>
                  <div class="basispro" v-if="semod == 2">
                    <el-select v-model="shopid" disabled filterable placeholder="请选择商品">
                      <el-option v-for="(item,index) in shoplists" :key="index" :label="item.title"
                        :value="item.id"></el-option>
                    </el-select>
                    <el-checkbox style="margin-left: 20px;" v-if="this.shop_id == 50481 || this.shop_id == 304676"
                      v-model="isxn">引流商品</el-checkbox>
                  </div>
                </div>
              </div>

              <div class="kflexc mb20">
                <div class="kflexc zuo180">

                  <div style="margin-right: 10px;"><span class="xing">*</span></div>
                  <div>商品名称:</div>
                </div>
                <div class="kflexc">
                  <div><el-input v-model="shopform.title" :class="{redbor:!sub3}" @change="nijiushiwodeweiyi3" placeholder="不超过30个字"></el-input></div>
                  <div>
                    <el-tooltip class="item" effect="light" content="对外展示的产品标题，能清晰描述概括产品，例：北京19元月租大王卡赠2GB流量"
                      placement="top">
                      <i class="el-icon-question"
                        style="color: rgb(64, 155, 250); font-size: 25px; margin-left: 20px; cursor: pointer;"></i>
                    </el-tooltip>
                  </div>
                </div>
              </div>

              <div class="kflexc mb20">
                <div class="kflexc zuo180">

                  <div style="margin-right: 10px;"><span class="xing">*</span></div>
                  <div>商家编码(抓单标识):</div>
                </div>
                <div class="kflexc">
                  {{randomnum}}
                  <el-button plain type="primary" size="small" style="margin: 0 10px;"
                    @click="randomlog = true">自定义</el-button>
                  <el-tooltip class="item" effect="light"
                    content="如果要使用自动抓单系统的话，请在电商平台将该码粘贴到产品后台的“货号（商品编码）”处。每个产品都有唯一标识" placement="top">
                    <i class="el-icon-question"
                      style="color: rgb(64, 155, 250); font-size: 25px;  cursor: pointer;"></i>
                  </el-tooltip>
                </div>
              </div>
            </div> -->
<!--            <div class="tilte">商品对外描述</div>
            <div class="con">

              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div>商品注意点:</div>
                </div>
                <div>
                  <el-input v-model="shopform.points" placeholder="输入商品注意点"></el-input>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div>商品卖点:</div>
                </div>
                <div class="kflexc">
                  <div><el-input v-model="shopform.selling_point" placeholder="输入卖点，使用逗号隔开"></el-input></div>
                  <div>
                    <el-tooltip class="item" effect="light" content="不超过3组词，例：资费低，流量大，免月租等，不宜过长" placement="top">
                      <i class="el-icon-question ico"></i>
                    </el-tooltip>
                  </div>
                </div>
              </div>




              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div>结算要求:</div>
                </div>
                <div>
                  <el-input v-model="shopform.commission_rule" placeholder="对外展示"></el-input>
                </div>
              </div>

              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div>产品主图:</div>
                </div>
                <div>
                  <chuantu2 v-if="chuantushow" ref="chuantu" :imgs="shopform.image1" @getimg="getimg"></chuantu2>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div>商品分享图:</div>
                </div>
                <div class="kflexc">
                  <div>
                    <chuantu v-if="chuantushow" ref="chuantu" :imgs="shopform.share_img" @getimg="getimg2"></chuantu>
                  </div>
                  <div>
                    <el-tooltip class="item" effect="light" content="该图用于微小店分享商品处向用户说明产品优点。" placement="top">
                      <i class="el-icon-question"
                        style="color: rgb(64, 155, 250); font-size: 25px;  margin-left: 20px; cursor: pointer;"></i>
                    </el-tooltip>
                  </div>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="xing">*</span></div>
                  <div>商品详情:</div>
                </div>
                <div>
                  <div id="editor" style="width: 1200px;"></div>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div>其他备注:</div>
                </div>
                <div>
                  <div id="editorE" style="width: 1200px;"></div>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div>强制同步:</div>
                </div>
                <div>
                  <el-checkbox v-model="force_update" @change="changeforce_update">强制同步分销商此商品详情页
                  </el-checkbox>
                </div>
              </div>


            </div> -->
            <div class="tilte">套餐详细信息</div>
            <div class="con">
              <div class="kflexc">
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>
                    <div>商品名称:</div>
                  </div>
                  <div>
                    <el-input v-model="shopform.goods_name" placeholder="商品名称"></el-input>
                  </div>
                </div>
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>
                    <div>运营商:</div>
                  </div>
                  <div>
                    <el-input v-model="shopform.operator" placeholder="运营商"></el-input>
                  </div>
                </div>
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>
                    <div>归属地:</div>
                  </div>
                  <div>
                    <el-input v-model="shopform.guishudi" placeholder="归属地"></el-input>
                    <!-- <dizhi @xuanzhongde="xuanzhongde" :guishudi_code="shopform.guishudi_code"></dizhi> -->
                  </div>
                </div>


              </div>
              <div class="kflexc">
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>

                    <div>优惠期月租:</div>
                  </div>
                  <div>
                    <el-input v-model="shopform.discount_rent" placeholder="优惠期月租"></el-input>
                  </div>
                </div>
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>

                    <div>优惠后月租:</div>
                  </div>
                  <div>
                    <el-input v-model="shopform.yuezu" placeholder="优惠后月租"></el-input>
                  </div>
                </div>
              </div>

              <div class="kflexc">
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>

                    <div>首充赠送金额:</div>
                  </div>
                  <div>
                    <el-input v-model="shopform.recharge_present" placeholder="首充赠送金额"></el-input>
                  </div>
                </div>
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>

                    <div>激活首月赠送金额:</div>
                  </div>
                  <div>
                    <el-input v-model="shopform.active_present" placeholder="激活首月赠送金额"></el-input>
                  </div>
                </div>
              </div>

              <div class="kflexc">
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>

                    <div>语音通话:</div>
                  </div>
                  <div>
                    <el-input v-model="shopform.yuyin" placeholder="语音通话"></el-input>
                  </div>
                </div>
                <div class="kflexc mb20">
                  <div class="kflexc zuo180">
                    <div style="margin-right: 10px;"><span class="ai">AI</span></div>

                    <div>协议期:</div>
                  </div>
                  <div>
                    <el-select v-model="shopform.agreed_period" placeholder="输入月" style=" margin-right: 10px;">
                      <el-option :value="item" v-for="item in 36" :key="item" :label="item + '个月'"></el-option>
                    </el-select>
                  </div>
                </div>
              </div>

              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="ai">AI</span></div>

                  <div>通用流量:</div>
                </div>
                <div>
                  <el-input v-model="shopform.liuliang" placeholder="通用流量"></el-input>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="ai">AI</span></div>

                  <div>定向流量:</div>
                </div>
                <div>
                  <el-input v-model="shopform.dx_liuliang" placeholder="定向流量"></el-input>
                </div>
              </div>
              <!-- <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="ai">AI</span></div>
                  <div>归属地:</div>
                </div>
                <div>
                  <dizhi @xuanzhongde="xuanzhongde" :guishudi_code="shopform.guishudi_code"></dizhi>
                </div>
              </div> -->
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="ai">AI</span></div>
                  <div>首充方式:</div>
                </div>
                <div>
                  <el-input v-model="shopform.recharge_type" placeholder="首充方式"></el-input>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="ai">AI</span></div>
                  <div>激活方式:</div>
                </div>
                <div>
                  <el-input v-model="shopform.active_type" placeholder="激活方式"></el-input>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="ai">AI</span></div>
                  <div>套餐优惠期:</div>
                </div>
                <div class="kflexc">
                  <el-select v-model="shopform.yuezu_time" placeholder="输入月"
                    style=" margin-right: 10px;">
                    <el-option :value="item" v-for="item in 36" :key="item" :label="item + '个月'"></el-option>
                  </el-select>
                  <div class="zuo180" style="margin-right: 10px;">优惠期起始时间：</div>
                  <div style="margin-right: 10px; color: rgb(147, 147, 147);">自激活起</div>
                  <el-select v-model="shopform.yuezu_type" placeholder="输入月"
                    style="margin-right: 10px;">
                    <el-option :value="1" label="当月"></el-option>
                    <el-option :value="2" label="次月"></el-option>
                    <el-option :value="3" label="第三月"></el-option>
                  </el-select>
                  <div style="margin-right: 10px; color: rgb(147, 147, 147);">开始</div>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">
                  <div style="margin-right: 10px;"><span class="ai">AI</span></div>
                  <div>套餐详细信息:</div>
                </div>
                <div>
                  <div id="editorE2" style="width: 1200px;">
                  </div>
                </div>
              </div>
            </div>
<!--            <div class="tilte">商品返费收益</div>
            <div class="con">
              <div class="kflexc mb20">
                <div class="kflexc zuo180">


                  <div style="margin-right: 10px;"><span class="xing">*</span></div>
                  <div>预估收益:</div>
                </div>
                <div>
                  <el-input v-model="shopform.expect_income" placeholder="预估收益"></el-input>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">


                  <div>佣金结算周期:</div>
                </div>
                <div class="kflexc">
                  <el-select v-model="shopform.yongjin_time" placeholder="输入月"
                    style="margin-right: 10px;">
                    <el-option :value="item" v-for="item in 36" :key="item" :label="item + '个月'"></el-option>
                  </el-select>
                  <div class="zuo180" style="margin-right: 10px;">结算起始时间：</div>
                  <div style="margin-right: 10px; color: rgb(147, 147, 147);">自激活起</div>
                  <el-select v-model="shopform.yongjin_type" placeholder="输入月"
                    style="margin-right: 10px;">
                    <el-option :value="1" label="当月"></el-option>
                    <el-option :value="2" label="次月"></el-option>
                    <el-option :value="3" label="第三月"></el-option>
                  </el-select>
                  <div style="margin-right: 10px; color: rgb(147, 147, 147);">开始</div>
                </div>
              </div>
              <div class="kflex mb20">
                <div class="kflex zuo180" style=" padding-top: 10px;">


                  <div>返利设置:</div>
                </div>
                <div>
                  <div class="kflexc" style="margin-bottom: 20px;">
                    <div><el-radio v-model="shopform.fanli_money_type" :label="0">每月相同反费额度</el-radio></div>
                    <div class="kflexc zhouqi" style="margin-left: 20px;">
                      <div style="color: rgb(147, 147, 147); margin-right: 10px;">返费周期:</div>
                      <div>
                        <el-select v-model="shopform.fanli_time" placeholder="输入月">
                          <el-option :value="item" v-for="item in 36" :key="item" :label="item + '个月'"></el-option>
                        </el-select>
                      </div>
                      <div style="margin-right: 10px; color: rgb(51, 51, 51); margin-left: 20px;">返利起始时间：</div>
                      <div style="margin-right: 10px; color: rgb(147, 147, 147);">自激活起</div>
                      <el-select v-model="shopform.fanli_type" placeholder="输入月" style=" margin-right: 10px;">
                        <el-option :value="1" label="当月"></el-option>
                        <el-option :value="2" label="次月"></el-option>
                        <el-option :value="3" label="第三月"></el-option>
                      </el-select>
                      <div style="margin-right: 10px; color: rgb(147, 147, 147);">开始</div>
                      <div style="margin-right: 10px; color: rgb(147, 147, 147);">每月返费金额</div>
                      <div style="margin-right: 10px; color: rgb(147, 147, 147);"><el-input
                          v-model="shopform.fanli_money" placeholder="请输入金额"></el-input></div>

                    </div>
                  </div>
                  <div class="kflexc" style=" margin-bottom: 20px;">
                    <div><el-radio v-model="shopform.fanli_money_type" :label="1">每月不同返费额度</el-radio></div>
                    <div style="margin-left: 20px;">
                      <div class="kflexc" v-for="(item,index) in fanli_money_array" :key="index"
                        style="margin-bottom: 10px;">
                        <div v-if="index == 0" class="zuo180">激活当月</div>
                        <div v-if="index == 1" class="zuo180">激活次月</div>
                        <div v-if="index != 0 && index != 1"  class="zuo180">第{{index+1}}个月</div>
                        <div style="margin-left: 10px;"><el-input v-model="fanli_money_array[index]" type="number"
                            placeholder="请输入金额"></el-input></div>
                      </div>
                      <el-button type="text" @click="changefanli_money_array()" style="margin-left: 180px;">+ 添加月份</el-button>
                    </div>
                  </div>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">

                  <div>返费方式:</div>
                </div>
                <div>
                  <el-select v-model="shopform.is_rebate" placeholder="输入返费方式" style="margin-right: 10px;">
                    <el-option :value="3" label="领取返费"></el-option>
                    <el-option :value="2" label="自动返费"></el-option>
                    <el-option :value="0" label="不使用返利系统"></el-option>
                  </el-select>
                </div>
              </div>
              <div class="kflexc mb20">
                <div class="kflexc zuo180">

                  <div>佣金备忘:</div>
                </div>
                <div>
                  <el-input v-model="shopform.commission_notes" placeholder="佣金备忘"></el-input>
                </div>
              </div>
            </div> -->


          </div>
          <div class="step" style="text-align: center;">
            <el-button type="danger" @click="jiancha()">确认修改</el-button>
          </div>

        </div>
      </div>
    </div>
    <el-dialog title="自定义抓单ID" :visible.sync="randomlog" width="400px">
      <div class="randomdiv">
        <el-input v-model="randomvalue" @input="randomnumwrite" placeholder="自定义抓单ID"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="randomlog = false">取 消</el-button>
        <el-button type="primary" @click="randomgo" :disabled="randomone">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="自定义产品类型" :visible.sync="taglog" width="400px">
      <div class="protag">
        <el-tag :key="item.id" v-for="item in typelist" closable :disable-transitions="false"
          @close="handleClose(item.name)">{{item.name}}</el-tag>
        <el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small"
          @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
        </el-input>
        <el-button v-else class="button-new-tag" size="small" @click="showInput">输入自定义名称</el-button>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- <foot></foot> -->
  </div>
</template>

<script>
  import {
    provinceAndCityDataPlus,
    provinceAndCityData,
    CodeToText,
    TextToCode
  } from 'element-china-area-data'
  import UploadExcelComponent from "@/components/UploadExcel/index.vue";
  import E from 'wangeditor'
  import axios from 'axios'
  import top from '@/components/top.vue'
  import left from '@/components/left.vue'
  import foot from '@/components/foot.vue'
  import dizhi from '@/views/yonghuyunying/zujian/dizhi.vue'
  import chuantu from "../../zujian/chuantu.vue";
  import chuantu2 from "../../zujian/chuantu2.vue";
  import zdzd from "../zdzd.vue";
  export default {
    components: {
      "left": left,
      "top": top,
      "foot": foot,
      UploadExcelComponent,
      dizhi,
      chuantu,
      chuantu2,
      zdzd
    },
    name: 'myDistributor',
    data() {
      return {
        chuantushow: false,
        taglog: false,
        taglist: ['类型1', '类型2'],
        inputVisible: false,
        inputValue: '',

        mingan: {
          city: "",
          citys: [],
          fixcitys: []
        },
        randomnum: "",
        jingdongrandom: "",
        search: "",
        msg: "hello",
        log: false,
        loading: true,

        typelist: {},
        citylist: provinceAndCityData,

        form: {
          produce_address: "",
          operator: "",
          name: "",
          sku: "",
          plan_type_id: "",
          province: "",
          city: [],
          citys: [],
          real_name_type: '0',
          produce_remark: "",
          status: "",
          comname: "",
          min_age: 18,
          max_purchase: 5,

          haochinum: 1,
          haochival: 1,

          address_province: "",
          address_city: "",
          address_district: "",
          commission_rule: "",
          commission_notes: "",
          fanli_money_array: ""
        },
        shopform: {
          product_id: "",
          title: "",
          status: "",
          parent_id: "",
          selling_point: "",
          commission_rule: "",
          commission_notes: "",
          is_need_photo: "0",
          description: "",
          pdd_description: "",
          image1: "",
          imageUrl: '',
          imageUrl2: '',
          details: {
            yuezu: "",
            liuliang: "",
            yuyin: "",
            quanyi: "",
            taocan: ""
          },
          expect_income: "",
          share_img: "",
          auto_transfer: '',
          auto_transfer_sources: [],
          auto_transfer_pages: [],

          discount_rent:"",
          recharge_present:"",
          active_present:"",
          recharge_type:"",
          active_type:"",
          agreed_period:"",

          goods_name:"",
          operator:""
        },
        moneyform: {
          order_page_id: "",
          visible: '1',
          commission: 0,
          child_shop_ids: "",
          dislist: "",
          money: "",
          list: ""
        },
        rules: {
          operator: [{
            required: true,
            message: '必选',
            trigger: 'change'
          }],
          name: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }],
          title: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }],
          proid: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }],
          sku: [{
            required: true,
            message: '必填',
            trigger: 'blur'
          }],
          city: [{
            required: true,
            message: '请选择活动区域',
            trigger: 'change'
          }],
          real_name_type: [{
            required: true,
            message: '请输入',
            trigger: 'change'
          }],
          randomnum: [{
            required: true,
            message: '请输入抓单码',
            trigger: 'change'
          }],
          // title: [{ required: true, message: '必填', trigger: 'change' }],
          is_need_photo: [{
            required: true,
            message: '必选',
            trigger: 'change'
          }],
          img: [{
            required: true,
            message: '必选',
            trigger: 'change'
          }],
          edit: [{
            required: true,
            message: '必填',
            trigger: 'change'
          }],
          visible: [{
            required: true,
            message: '必选',
            trigger: 'change'
          }],
          commission: [{
            required: true,
            message: '必选',
            trigger: 'change'
          }],
        },
        kejian: false,
        sub1: true,
        sub2: true,
        sub3: true,
        sub4: true,
        showmoney: false,
        sanlist: [
          // {
          //   name: "中国联通",
          //   id: 10000
          // },
          // {
          //   name: "中国移动",
          //   id: 10086
          // },
          // {
          //   name: "中国电信",
          //   id: 10010
          // },
          {
            name: "中国广电",
            id: 10099
          }
        ],
        randomvalue: "",
        randomone: false,
        randomlog: false,

        shop_id: "",
        abstract: "",
        statusshop: false,

        prolists: [],


        basis: 0,
        basislog: false,
        proid: "",
        shopid: "",
        shoplists: {},
        basisshop: "",
        semod: 1,
        force_update: false,
        force_updateshow: false,
        shop: "",
        split_list: [],
        cishu: 0,
        cd_type_radio: 4,
        cd_number: "0",
        guishudi_all: "",

        provinceData: provinceAndCityData,
        cityData: [],
        provinceText: '',
        cityText: '',
        isxn: false,

        fanli_money_array: []
      }
    },
    created() {
      //权限问题
      var user = JSON.parse(localStorage.getItem('USER'));
      this.shop = user.id
      //获取分销商
      this.getdislist()

      if(this.$route.query.id){
        this.getpeizhi()
      }

      //获取类型
      this.getproductstype();
      this.getpros();
      this.getshops()
      axios.get('/api/gth/user/shop')
        .then(response => {
          if (response.data.msg.code == 0) {
            this.shop_id = response.data.data.shop_id
          } else {
            if (response.data.msg.code == 50401) {
              that.$router.push({
                path: "/login"
              });
              return false
            }
            that.$message.error(response.data.msg.info);
          }
        })
    },
    mounted() {

      this.citylist.forEach(item => {
        if (item.label == '北京市') {
          item.children.forEach(item => {
            item.label = '北京市'
          })
        }
        if (item.label == '上海市') {
          item.children.forEach(item => {
            item.label = '上海市'
          })
        }
        if (item.label == '重庆市') {
          item.children.forEach(item => {
            item.label = '重庆市'
          })
        }
        if (item.label == '天津市') {
          item.children.forEach(item => {
            item.label = '天津市'
          })
        }
      })

      var that = this
      var editor = new E('#editor');
      editor.customConfig.uploadImgServer = '/upload'
      editor.customConfig.showLinkImg = false
      editor.customConfig.onchange = function(html) {
        that.shopform.description = html
      }
      editor.customConfig.customUploadImg = function(files, insert) {
        var formData = new FormData();
        formData.append("pic", files[0]);
        axios.post('/api/plan-market/order-page/upload-pic', formData)
          .then(response => {
            if (response.data.msg.code == 0) {
              insert(response.data.data)

            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      }
      editor.create();

      //其它备注
      var editorE = new E('#editorE');
      editorE.customConfig.uploadImgServer = '/upload'
      editorE.customConfig.showLinkImg = false
      editorE.customConfig.onchange = function(html) {
        that.shopform.pdd_description = html
      }
      editorE.customConfig.customUploadImg = function(files, insert) {
        var formData = new FormData();
        formData.append("pic", files[0]);
        axios.post('/api/plan-market/order-page/upload-pic', formData)
          .then(response => {
            if (response.data.msg.code == 0) {
              insert(response.data.data)

            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      }
      editorE.create();

      //套餐详细信息
      var editorE2 = new E('#editorE2');
      editorE2.customConfig.uploadImgServer = '/upload'
      editorE2.customConfig.showLinkImg = false
      editorE2.customConfig.onchange = function(html) {
        that.shopform.package_text = html
      }
      editorE2.customConfig.customUploadImg = function(files, insert) {
        var formData = new FormData();
        formData.append("pic", files[0]);
        axios.post('/api/plan-market/order-page/upload-pic', formData)
          .then(response => {
            if (response.data.msg.code == 0) {
              insert(response.data.data)
            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      }
      editorE2.create();

      //获取商品详情后追加内容
      var that = this;
      axios.get('/api/plan-market/order-page?order_page_id=' + this.$route.query.id)
        .then(response => {
          if (response.data.msg.code == 0) {

            if (response.data.data.selling_point && response.data.data.selling_point != '') {
              response.data.data.selling_point = response.data.data.selling_point.toString()
            } else {
              response.data.data.selling_point = ''
            }

            if (response.data.data.is_need_photo == "0") {
              response.data.data.is_need_photo = "0"
            }
            if (response.data.data.is_need_photo == "1") {
              response.data.data.is_need_photo = "1"
            }
            that.randomnum = response.data.data.fetch_code
            that.jingdongrandom = response.data.data.fetch_code2
            that.shopform = response.data.data
            if (response.data.data.status == 0) {
              that.statusshop = false
            } else {
              that.statusshop = true
            }
            editor.txt.html(that.shopform.description)
            editorE.txt.html(that.shopform.pdd_description)
            editorE2.txt.html(that.shopform.package_text)


            if (that.shopform.parent_id == 0) {
              that.semod = '1'
              that.proid = that.shopform.product_id
            } else {
              that.semod = '2'
              that.shopid = that.shopform.parent_id
            }

            if (that.shopform.parent_id == 0) {
              that.force_updateshow = true
            }
            if (that.shopform.details) {
              that.shopform.details = JSON.parse(that.shopform.details)
            } else {
              that.shopform.details = {
                yuezu: "",
                liuliang: "",
                yuyin: "",
                quanyi: "",
                taocan: ""
              }
            }

            // var city = []
            // if(this.shopform.guishudi_province != "" && this.shopform.guishudi_province != null && this.shopform.guishudi_province != "全部"){
            // 	city.push(TextToCode[this.shopform.guishudi_province].code)
            // }
            // if(this.shopform.guishudi_city != "" && this.shopform.guishudi_city != null){
            // 	city.push(TextToCode[this.shopform.guishudi_province][this.shopform.guishudi_city].code)
            // }
            // this.guishudi_all = city

            if (that.shopform.guishudi_province) {
              that.provinceText = TextToCode[that.shopform.guishudi_province].code
              that.handleChangeProvince(that.provinceText)
            }
            if (that.shopform.guishudi_city) {

              that.cityText = TextToCode[that.shopform.guishudi_province][that.shopform.guishudi_city].code

            }

            if (that.shopform.is_virtually == 1) {
              that.isxn = true
            } else {
              that.isxn = false
            }

            that.chuantushow = true
            if (that.shopform.fanli_money_array) {
              that.fanli_money_array = that.shopform.fanli_money_array.split(',')
            }

            that.loading = false

          } else {
            that.$message.error(response.data.msg.info);
          }
        })

    },
    methods: {
      //添加月份
      changefanli_money_array: function() {
        this.fanli_money_array.push(0)
      },
      getimg: function(img) {
        this.shopform.image1 = img
      },
      getimg2: function(img) {
        this.shopform.share_img = img
      },
      xuanzhongde: function(item) {
        this.shopform.guishudi = item.zi
        this.shopform.guishudi_code = item.shu
        // this.all.province = item
      },
      // handleChangeProvince(value) {
      //       this.cityData = []
      //       this.cityText = ''
      //       const province = CodeToText[value]
      //       if (province === '北京市' || province === '天津市' || province === '上海市' || province === '重庆市' ||
      //         province === '香港特别行政区' || province === '澳门特别行政区') {
      //         const city = { value: value, label: province }
      //         this.cityData.push(city)
      //       } else {
      //         const childList = this.provinceData.find(i => i.value === value).children
      //         this.cityData.push(...childList)
      //       }
      //       console.log(this.provinceText,this.cityText)
      // },
      // guishudi:function(val){
      //   if(val[0] == '全部'){
      //     this.shopform.guishudi_province = ''
      //   }else{
      //     this.shopform.guishudi_province = CodeToText[val[0]]
      //   }
      //   if(val[1] == '全部'){
      //     this.shopform.guishudi_city = ''
      //   }else{
      //     this.shopform.guishudi_city = CodeToText[val[1]]
      //   }
      // },
      jiancha: function() {

        let arr = []
        if (this.split_list.length != 0) {

          this.split_list.forEach(item => {
            arr.push(item.sku)
          })

          axios.post('/api/plan-market/shop/skus/check', {
              skus: arr
            })
            .then(response => {
              if (response.data.msg.code == 0) {
                this.shopsave()
                this.loading = false
              } else {
                this.loading = false
                this.$message.error('拆分订单所属商品' + response.data.msg.info);
              }
            })

        } else {
          this.shopsave()
          this.loading = false
        }



        // this.loading = true
        // if(this.split_list.length != 0){
        // 	this.checksku(this.split_list[0].sku)
        // }else{
        // 	this.shopsave()
        // 	this.loading = false
        // }
      },
      checksku: function(sku) {

        // axios.post('/api/plan-market/shop/sku/check',{sku:sku})
        // 	.then(response => {
        // 		if (response.data.msg.code == 0) {
        // 			this.cishu++
        // 			if(this.cishu == this.split_list.length){
        // 				this.shopsave()
        // 				this.cishu = 0
        // 				this.loading = false
        // 			}else{
        // 				this.checksku(this.split_list[this.cishu].sku)
        // 			}
        // 		} else {
        // 			this.cishu = 0
        // 			this.loading = false
        // 			this.$message.error(sku + response.data.msg.info);
        // 			return false
        // 		}
        // 	})
      },
      getpeizhi: function() {
        axios.get('/api/plan-market/split/configs2?page_id=' + this.$route.query.id)
          .then(response => {
            if (response.data.msg.code == 0) {

              if (response.data.data.length == 0) {
                this.cd_number = '0'
              } else {
                this.cd_number = response.data.data.length
              }

              this.split_list = response.data.data
              this.split_list.forEach(item => {
                if (item.check_deliver == 1) {
                  item.check_deliver = true
                  this.cd_type_radio = 4
                } else if (item.check_deliver == 0) {
                  item.check_deliver = false
                  this.cd_type_radio = 4
                } else if (item.check_deliver == 2) {
                  this.cd_type_radio = 3
                }
              })

            } else {
              this.$message.error(response.data.msg.info);
              return false
            }
          })
      },
      changenumber: function(val) {
        let v = val - this.split_list.length
        if (v > 0) {
          for (let i = 0; i < v; i++) {
            // 当前商品id  拆单商品sku 第几个拆单  是否检测发货1检测0不 later是多少小时后拆单 1=1小时
            this.split_list.push({
              page_id: "",
              sku: "",
              split_number: "",
              check_deliver: "",
              later: ""
            })
          }
        } else {
          this.split_list.length = val
        }
      },
      //强制同步
      changeforce_update: function() {
        console.log("a")
        this.$confirm('勾选后下游所有该商品的下游详情页将同步更新, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.force_update = true
        }).catch(() => {
          this.force_update = false
        })
      },
      //更换基础产品
      // basisgo:function(){
      // 	this.loading = true
      // 	var that = this
      // 	if( this.basis == 0){
      // 		axios.post('/api/plan-market/page/product/update',{product_id:this.proid,page_id:this.chooseid})
      // 			.then(response => {
      // 				if(response.data.msg.code == 0){
      // 					that.$message.success("修改成功");
      // 					that.getpro()
      // 					that.basislog = false
      // 				}else{
      // 					that.$message.error(response.data.msg.info);
      // 				}
      // 			})
      // 	}
      // 	if( this.basis == 1){
      // 		axios.post('/api/plan-market/page/product/update',{parent_page_id:this.shopid,page_id:this.chooseid})
      // 			.then(response => {
      // 				if(response.data.msg.code == 0){
      // 					that.$message.success("修改成功");
      // 					that.getpro()
      // 					that.basislog = false
      // 				}else{
      // 					that.$message.error(response.data.msg.info);
      // 				}
      // 			})
      // 	}
      // },
      // getallshop:function(){
      // 	if( this.basis == 0){this.getpros()}
      // 	if( this.basis == 1){this.getshops()}
      // },
      //获取全部基础产品
      getpros: function() {
        var that = this
        axios.get('/api/gth/products/list?page_size=10000')
          .then(response => {
            if (response.data.msg.code == 0) {
              that.prolists = response.data.data.data
              // for(var i in response.data.data.data){
              // 	var obj = {
              // 		name:response.data.data.data[i].name,
              // 		id:response.data.data.data[i].id
              // 	}
              // 	that.prolists.push(obj)
              // }
              // this.getshops()
            } else {
              that.$message.error(response.data.msg.info);
            }
          })

      },
      getshops: function() {
        //获取商品
        var that = this;
        axios.get('/api/gth/supplier/products?page_size=1000')
          .then(response => {
            if (response.data.msg.code == 0) {
              that.shoplists = response.data.data.data
              // for(var i in response.data.data.data){
              // 	var obj = {
              // 		name:response.data.data.data[i].title,
              // 		id:response.data.data.data[i].id
              // 	}
              // 	that.prolists.push(obj)

              // }
            } else {
              if (response.data.msg.code == 50401) {
                that.$router.push({
                  path: "/login"
                });
                return false
              }
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //自定义抓单码唯一性
      randomnumwrite: function() {
        var that = this
        axios.get('/api/plan-market/order-page/fetch-code/isexist?fetch_code=' + this.randomvalue)
          .then(response => {
            if (response.data.msg.code == 0) {
              that.randomone = false
            } else {
              that.randomone = true
            }
          })
      },
      //自定义抓单码点击确认
      randomgo: function() {
        this.randomnum = this.randomvalue
        this.randomlog = false
      },
      //获取产品详情
      getprodetail: function() {
        var that = this;
        axios.get('/api/plan-market/product?product_id=' + this.$route.query.productid)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.form = response.data.data

              if (this.form.real_name_type == 0) {
                this.form.real_name_type = "0"
              }
              if (this.form.real_name_type == 1) {
                this.form.real_name_type = "1"
              }

              this.mingan.citys = this.form.warn_province
              this.mingan.fixcitys = this.form.warn_city



              var city = []
              if (this.form.province != "") {
                city.push(TextToCode[this.form.province].code)
              }
              if (this.form.city != "") {
                city.push(TextToCode[this.form.province][this.form.city].code)
              }
              this.form.citys = city


            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      },

      //获取商品品详情
      getshopdetail: function() {
        var that = this;
        axios.get('/api/plan-market/order-page?order_page_id=' + this.$route.query.id)
          .then(response => {
            if (response.data.msg.code == 0) {
              var arr = ""
              for (var i in response.data.data.selling_point) {
                arr = arr + response.data.data.selling_point[i]
              }
              response.data.data.selling_point = arr

              if (response.data.data.is_need_photo == "0") {
                response.data.data.is_need_photo = "0"
              }
              if (response.data.data.is_need_photo == "1") {
                response.data.data.is_need_photo = "1"
              }
              that.randomnum = response.data.data.fetch_code
              that.shopform = response.data.data

            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      },


      //修改佣金时执行全部佣金赋值并保存后重新获取一下列表和佣金
      fixallmoney: function() {
        var that = this;
        var formData = new FormData();
        formData.append("order_page_id", this.moneyform.order_page_id);
        formData.append("visible", this.moneyform.visible);
        formData.append("commission", this.moneyform.commission);
        formData.append("child_shop_ids", this.moneyform.child_shop_ids);

        axios.post('/api/gth/order-page/visible', formData)
          .then(response => {
            if (response.data.msg.code == 0) {
              that.getmoneylist();
            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //个性化编辑佣金
      fixmoney: function(i, id) {
        this.$prompt('请输入金额', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(response => {
          var that = this;
          var formData = new FormData();
          formData.append("order_page_id", that.moneyform.order_page_id);
          formData.append("child_shop_id", id);
          formData.append("commission", response.value);

          axios.post('/api/plan-market/order-page/commissions/update', formData)
            .then(response => {
              if (response.data.msg.code == 0) {
                this.getmoneylist();
                that.$message({
                  message: '保存成功！',
                  type: 'success'
                });
              } else {
                that.$message.error(response.data.msg.info);
              }
            })
        })
      },
      //获取分销商和佣金
      getmoneylist: function() {
        var that = this;
        axios.get('/api/plan-market/order-page/commissions?order_page_id=' + that.moneyform.order_page_id)
          .then(response => {
            if (response.data.msg.code == 0) {
              that.moneyform.list = response.data.data.data
            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      },

      chakan: function() {
        console.log(this.moneyform.child_shop_ids)
      },
      //产品名验证唯一性
      nijiushiwodeweiyi1: function() {
        var that = this;
        axios.get('/api/plan-market/product/name/isexist?name=' + that.form.name)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.sub1 = true
            } else {
              this.sub1 = false
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //产品编号验证唯一性
      nijiushiwodeweiyi2: function() {
        var that = this;
        axios.get('/api/plan-market/product/sku/isexist?sku=' + this.form.sku)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.sub2 = true
            } else {
              this.sub2 = false
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //商品名验证唯一性
      nijiushiwodeweiyi3: function() {
        var that = this;
        axios.get('/api/plan-market/order-page/name/isexist?title=' + this.shopform.title)
          .then(response => {
            if (response.data.msg.code == 0) {
              this.sub3 = true
            } else {
              this.sub3 = false
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //京东唯一性
      nijiushiwodeweiyi4: function() {
        this.jingdongrandom = this.jingdongrandom.trim()
        if (this.jingdongrandom == "") {
          this.sub4 = true
        } else {
          var that = this;
          axios.get('/api/plan-market/order-page/fetch-code?fetch_code2=' + this.jingdongrandom)
            .then(response => {
              if (response.data.msg.code == 0) {
                this.sub4 = true
              } else {
                this.sub4 = false
                that.$message.error(response.data.msg.info);
              }
            })
        }

      },
      //身份证审核
      cardid: function() {
        this.moneyform.child_shop_ids = "";
        if (this.moneyform.visible == 3 || this.moneyform.visible == 4) {
          this.kejian = true
        }
        if (this.moneyform.visible == 1 || this.moneyform.visible == 2) {
          this.kejian = false
        }
      },
      //获取全部分销商
      getdislist: function() {
        var that = this;
        axios.get('/api/gth/partner/list?page_size=10000')
          .then(response => {
            if (response.data.msg.code == 0) {
              that.moneyform.dislist = response.data.data.data
            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //保存产品
      productsave: function() {
        //发布还是仅保存

        console.log(this.mingan.citys)
        if (this.form.address_province == undefined) {
          this.form.address_province = this.form.province
          this.form.address_city = this.form.city
        }

        var that = this;
        var formData = {
          product_id: this.$route.query.productid,
          name: this.form.name,
          sku: this.form.sku,
          operator: this.form.operator,
          plan_type_id: this.form.plan_type_id,
          province: this.form.address_province,
          city: this.form.address_city,
          real_name_type: this.form.real_name_type,
          produce_remark: this.form.produce_remark,
          max_purchase: this.form.max_purchase,
          min_age: this.form.max_purchase,
          // status:this.form.status,
          produce_address: this.form.produce_address,
          commission_rule: this.form.commission_rule,
          commission_notes: this.form.commission_notes,

          warn_province: this.mingan.citys,
          warn_city: this.mingan.fixcitys,
          abstract: this.abstract
        }
        axios.post('/api/plan-market/product', formData)
          .then(response => {
            if (response.data.msg.code == 0) {
              that.shopform.product_id = response.data.data.id
              //成功获取到产品id后执行保存商品
              that.shopsave();

            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      },
      //保存商品
      shopsave: function() {
        if(!this.shopform.expect_income){
          this.$message.error("预估收益必填");
          return false
        }
        if (this.sub4 == false) {
          return false
        }
        if (this.jingdongrandom == "" || this.jingdongrandom == null) {

        } else {
          if (this.jingdongrandom.length != 3) {
            this.$message.error("京东抓单码必须三位或者不填写");
            return false
          }
        }
        var that = this;
        // if(this.basis == 0){
        // 	product_id:this.proid
        // 	page_id:this.chooseid
        // 	parent_page_id:this.shopid
        // 	page_id:this.chooseid
        // }

        if (this.provinceText) {
          this.shopform.guishudi_province = CodeToText[this.provinceText]
        } else {
          this.shopform.guishudi_province = ""
        }
        if (this.cityText) {
          this.shopform.guishudi_city = CodeToText[this.cityText]
        } else {
          this.shopform.guishudi_city = ""
        }

        if (this.shopform.auto_transfer_pages.length) {
          if (this.shopform.auto_transfer_pages[0].title == undefined) {
            var new_auto_transfer_pages = this.shopform.auto_transfer_pages
          } else {


            var new_auto_transfer_pages = []
            for (var x = 0; x < this.shopform.auto_transfer_pages.length; x++) {
              new_auto_transfer_pages.push(this.shopform.auto_transfer_pages[x].id)
            }
          }
        } else {
          var new_auto_transfer_pages = this.shopform.auto_transfer_pages
        }

        var formData = {
          order_page_id: this.$route.query.id,
          title: this.shopform.title,
          selling_point: this.shopform.selling_point,
          commission_rule: this.shopform.commission_rule,
          commission_notes: this.shopform.commission_notes,

          is_need_photo: this.shopform.is_need_photo,
          description: this.shopform.description,
          pdd_description: this.shopform.pdd_description,
          image1: this.shopform.image1,
          fetch_code: this.randomnum,
          status: this.shopform.status,
          fetch_code2: this.jingdongrandom,
          abstract: this.abstract,
          force_update: this.force_update,
          details: JSON.stringify(this.shopform.details),
          expect_income: this.shopform.expect_income,
          // guishudi_province: this.shopform.guishudi_province,
          // guishudi_city: this.shopform.guishudi_city,
          guishudi: this.shopform.guishudi,
          guishudi_code: this.shopform.guishudi_code,
          yuezu: this.shopform.yuezu,
          liuliang: this.shopform.liuliang,
          yuyin: this.shopform.yuyin,
          yuezu_time: this.shopform.yuezu_time,
          yuezu_type: this.shopform.yuezu_type,
          yongjin_time: this.shopform.yongjin_time,
          yongjin_type: this.shopform.yongjin_type,
          fanli_time: this.shopform.fanli_time,
          fanli_type: this.shopform.fanli_type,
          share_img: this.shopform.share_img,
          dx_liuliang: this.shopform.dx_liuliang,
          package_text: this.shopform.package_text,
          points: this.shopform.points,
          fanli_money: this.shopform.fanli_money,
          is_rebate: this.shopform.is_rebate,
          auto_transfer: this.shopform.auto_transfer,
          auto_transfer_sources: this.shopform.auto_transfer_sources,
          auto_transfer_pages: new_auto_transfer_pages,
          fanli_money_type: that.shopform.fanli_money_type,
          fanli_money_array: that.fanli_money_array.toString(),

          discount_rent: that.shopform.discount_rent,
          goods_name: that.shopform.goods_name,
          operator: that.shopform.operator,
          recharge_present:that.shopform.recharge_present,
          active_present:that.shopform.active_present,
          recharge_type:that.shopform.recharge_type,
          active_type:that.shopform.active_type,
          agreed_period:that.shopform.agreed_period
        }
        if (this.semod == 1) {
          formData['product_id'] = this.proid
        } else {
          formData['parent_id'] = this.shopid
        }

        if (this.isxn == true) {
          formData['is_virtually'] = 1
        } else {
          formData['is_virtually'] = 0
        }


        axios.post('/api/plan-market/order-page', formData)
          .then(response => {
            if (response.data.msg.code == 0) {
              //添加拆单设置
              // if(this.split_list != ''){
              this.split_list.forEach((item, index) => {
                if (this.cd_type_radio == 3) {
                  //按条件拆单
                  item.check_deliver = 2
                  item.later = "0"
                } else if (this.cd_type_radio == 4) {
                  //按时间拆单
                  if (item.check_deliver == true) {
                    item.check_deliver = 1
                  } else {
                    item.check_deliver = 0
                  }
                }

                item.page_id = this.$route.query.id
                item.split_number = index + 1
              })
              let datas = {
                data: this.split_list,
                page_id: this.$route.query.id
              }

              axios.post('/api/plan-market/split/config2', datas)
                .then(response2 => {
                  if (response2.data.msg.code == 0) {
                    //下架商品
                    if (that.shopform.status == 0) {
                      that.$message({
                        message: '修改成功！',
                        type: 'success'
                      });
                      that.$router.push({
                        path: '/productionDelivery/productionDeliverysale'
                      })
                    } else {
                      //上架商品
                      if (this.shop_id == 50481 || this.shop_id == 304676) {
                        if (this.statusshop == true) {
                          that.$message({
                            message: '商品已提交审核！',
                            type: 'success'
                          });
                          that.$router.push({
                            path: '/productionDelivery'
                          })
                        } else {
                          that.$message({
                            message: '修改成功！',
                            type: 'success'
                          });
                          that.$router.push({
                            path: '/productionDelivery'
                          })
                        }

                      } else {
                        that.$message({
                          message: '修改成功！',
                          type: 'success'
                        });
                        that.$router.push({
                          path: '/productionDelivery'
                        })
                      }
                    }
                  } else {
                    this.$message.error(response2.data.msg.info);
                    return false
                  }
                })
              // }else{
              // 	//下架商品
              // 	if (that.shopform.status == 0) {
              // 		that.$message({
              // 			message: '修改成功！',
              // 			type: 'success'
              // 		});
              // 		that.$router.push({
              // 			path: '/productionDeliverysale'
              // 		})
              // 	} else {
              // 		//上架商品
              // 		if (this.shop_id == 50481 || this.shop_id == 304676) {
              // 			if (this.statusshop == true) {
              // 				that.$message({
              // 					message: '商品已提交审核！',
              // 					type: 'success'
              // 				});
              // 				that.$router.push({
              // 					path: '/productionDelivery'
              // 				})
              // 			} else {
              // 				that.$message({
              // 					message: '修改成功！',
              // 					type: 'success'
              // 				});
              // 				that.$router.push({
              // 					path: '/productionDelivery'
              // 				})
              // 			}

              // 		} else {
              // 			that.$message({
              // 				message: '修改成功！',
              // 				type: 'success'
              // 			});
              // 			that.$router.push({
              // 				path: '/productionDelivery'
              // 			})
              // 		}
              // 	}
              // }



            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      },

      //绑定佣金分销商
      bangding: function() {
        var that = this;
        var formData = new FormData();
        formData.append("order_page_id", this.moneyform.order_page_id);
        formData.append("visible", this.moneyform.visible);
        formData.append("commission", this.moneyform.commission);
        formData.append("child_shop_ids", this.moneyform.child_shop_ids);

        axios.post('/api/gth/order-page/visible', formData)
          .then(response => {
            if (response.data.msg.code == 0) {
              console.log(that.form.status)
              if (that.form.status == 0) {
                that.$message({
                  message: '修改成功！',
                  type: 'success'
                });
                that.$router.push({
                  path: '/productionDelivery'
                })
              } else {
                if (this.shop_id == 50481 || this.shop_id == 304676) {
                  that.$message({
                    message: '商品已提交审核！',
                    type: 'success'
                  });
                  that.$router.push({
                    path: '/productionDelivery'
                  })
                } else {
                  that.$message({
                    message: '修改成功！',
                    type: 'success'
                  });
                  that.$router.push({
                    path: '/productionDelivery'
                  })
                }
              }
            } else {
              that.$message.error(response.data.msg.info);
            }
          })
      },

      dataURLtoFile(dataurl, filename) {
        let arr = dataurl.split(","),
          mime = arr[0].match(/:(.*?);/)[1],
          bstr = atob(arr[1]),
          n = bstr.length,
          u8arr = new Uint8Array(n);
        while (n--) {
          u8arr[n] = bstr.charCodeAt(n);
        }
        return new File([u8arr], filename, {
          type: mime
        });
      },
      //单个图片上传
      uploadok: function(file) {
        var that = this;
        console.log(file.raw)
        var reader = new FileReader()
        var img = new Image();
        reader.onload = function(e) {
          img.src = e.target.result;
        };
        var canvas = document.createElement('canvas');
        var context = canvas.getContext('2d');
        // base64地址图片加载完毕后
        let p = new Promise((r, j) => {
          img.onload = function() {
            // 图片原始尺寸
            var originWidth = this.width;
            var originHeight = this.height;
            // 最大尺寸限制
            var maxWidth = 1920,
              maxHeight = 1080;
            // 目标尺寸
            var targetWidth = originWidth,
              targetHeight = originHeight;
            // 图片尺寸超过400x400的限制
            if (originWidth > maxWidth || originHeight > maxHeight) {
              if (originWidth / originHeight > maxWidth / maxHeight) {
                // 更宽，按照宽度限定尺寸
                targetWidth = maxWidth;
                targetHeight = Math.round(maxWidth * (originHeight / originWidth));
              } else {
                targetHeight = maxHeight;
                targetWidth = Math.round(maxHeight * (originWidth / originHeight));
              }
            }
            // canvas对图片进行缩放
            canvas.width = targetWidth;
            canvas.height = targetHeight;
            // 清除画布
            context.clearRect(0, 0, targetWidth, targetHeight);
            // 图片压缩
            context.drawImage(img, 0, 0, targetWidth, targetHeight);

            let base64 = canvas.toDataURL("image/jpeg", 0.8); // 压缩后的base64图片
            let file2 = that.dataURLtoFile(base64, Date.parse(Date()) + ".jpg");
            r(file2)
          };
        })
        reader.readAsDataURL(file.raw);
        p.then(files => {
          var formData = new FormData();
          formData.append("pic", files);
          axios.post('/api/plan-market/order-page/upload-pic', formData)
            .then(response => {
              if (response.data.msg.code == 0) {
                that.shopform.image1 = response.data.data
              } else {
                that.$message.error(response.data.msg.info);
              }
            })
        })
      },
      uploadok2: function(file) {
        var that = this;
        console.log(file.raw)
        var reader = new FileReader()
        var img = new Image();
        reader.onload = function(e) {
          img.src = e.target.result;
        };
        var canvas = document.createElement('canvas');
        var context = canvas.getContext('2d');
        // base64地址图片加载完毕后
        let p = new Promise((r, j) => {
          img.onload = function() {
            // 图片原始尺寸
            var originWidth = this.width;
            var originHeight = this.height;
            // 最大尺寸限制
            var maxWidth = 1920,
              maxHeight = 10800;
            // 目标尺寸
            var targetWidth = originWidth,
              targetHeight = originHeight;
            // 图片尺寸超过400x400的限制
            if (originWidth > maxWidth || originHeight > maxHeight) {
              if (originWidth / originHeight > maxWidth / maxHeight) {
                // 更宽，按照宽度限定尺寸
                targetWidth = maxWidth;
                targetHeight = Math.round(maxWidth * (originHeight / originWidth));
              } else {
                targetHeight = maxHeight;
                targetWidth = Math.round(maxHeight * (originWidth / originHeight));
              }
            }
            // canvas对图片进行缩放
            canvas.width = targetWidth;
            canvas.height = targetHeight;
            // 清除画布
            context.clearRect(0, 0, targetWidth, targetHeight);
            // 图片压缩
            context.drawImage(img, 0, 0, targetWidth, targetHeight);

            let base64 = canvas.toDataURL("image/jpeg", 0.8); // 压缩后的base64图片
            let file2 = that.dataURLtoFile(base64, Date.parse(Date()) + ".jpg");
            r(file2)
          };
        })
        reader.readAsDataURL(file.raw);
        p.then(files => {
          var formData = new FormData();
          formData.append("pic", files);
          axios.post('/api/plan-market/order-page/upload-pic', formData)
            .then(response => {
              if (response.data.msg.code == 0) {
                that.shopform.share_img = response.data.data
                console.log(that.shopform.share_img)
              } else {
                that.$message.error(response.data.msg.info);
              }
            })
        })
      },
      //选择省市区
      changeaddress: function(v) {
        this.form.address_province = CodeToText[v[0]],
          this.form.address_city = CodeToText[v[1]],
          console.log("选中的省市" + this.form.address_province + this.form.address_city)
      },
      //导入敏感地区
      exportData: function(data) {
        console.log(data)
        this.mingan.citys = []
        this.mingan.fixcitys = []
        for (var i = 0; i < data.results.length; i++) {
          this.mingan.citys.push(data.results[i]['敏感地区'])
          if (data.results[i]['修改敏感地区'].indexOf(",") > -1) {
            var arr = data.results[i]['修改敏感地区'].split(',')
          } else if (data.results[i]['修改敏感地区'].indexOf("，") > -1) {
            var arr = data.results[i]['修改敏感地区'].split('，')
          } else {
            return false
            that.$message.error("数据出错了，请检查格式");
          }
          var obj = {}
          obj[arr[0]] = arr[1]
          this.mingan.fixcitys.push(obj)
        }
      },
      //获取产品类型
      getproductstype: function() {
        var that = this
        axios.get("/api/gth/plan-type")
          .then(function(response) {
            if (response.data.msg.code == 0) {
              that.typelist = response.data.data
            } else {
              that.$message.error(response.data.msg.info);
            }

          })
      },

      loggo: function() {
        console.log("a")
      },

      //自定义产品类型
      handleClose(tag) {
        this.taglist.splice(this.taglist.indexOf(tag), 1);
      },

      showInput() {
        this.inputVisible = true;
        this.$nextTick(_ => {
          this.$refs.saveTagInput.$refs.input.focus();
        });
      },

      handleInputConfirm() {
        var that = this;
        var formData = new FormData();
        formData.append("name", this.inputValue);
        axios.post('/api/gth/plan-type/release', formData)
          .then(response => {
            if (response.data.msg.code == 0) {
              that.getproductstype();
              that.$message({
                message: '添加成功',
                type: 'success'
              });
            } else {
              that.$message.error(response.data.msg.info);
            }
          })
        let inputValue = this.inputValue;
        if (inputValue) {
          this.taglist.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = '';
      },
      // ======监听
      changesw(val) {
        //修改自动转单
        console.log(val)
        this.shopform.auto_transfer = val
      },
      surecreate(val) {
        //设置转单目标商品：
        console.log(val)
        var arr = []
        for (var x = 0; x < val.length; x++) {
          arr.push(val[x].id)
        }
        this.shopform.auto_transfer_pages = arr
      },
      handleChange(val) {
        //设置转单订单来源
        console.log(val)
        this.shopform.auto_transfer_sources = val

      }
    }

  }
</script>

<style lang="scss" scoped>
  /deep/ .el-input__inner {
    background: #F3F5F8 !important;
    border: 1px #F3F5F8 solid;
  }

  .bai {
    /deep/ .el-input__inner {
      background: #fff !important;
      border: 1px #fff solid !important;
    }
  }

  /deep/ .el-icon-question {
    font-size: 18px !important;
    color: #0C83FF !important;
  }

  /deep/ .el-input .el-input__inner {
    width: 300px;
  }





  /deep/ .w-e-menu {
    z-index: 1001 !important;
  }

  /deep/ .w-e-text-container {
    z-index: 1000 !important;
  }

  .index {



    /deep/ .el-message-box__wrapper {
      z-index: 20000 !important;
    }

    /deep/ #editorE {
      position: relative;
      z-index: 9;
    }

    /deep/ #editor {
      position: relative;
      z-index: 9;

      ::v-deep .w-e-text-container {
        z-index: 9;
      }

      ::v-deep .w-e-toolbar .w-e-menu {
        z-index: 9;
      }
    }

    .zhouqi { color: #666; font-size: 14px;
      /deep/ .el-input .el-input__inner {
        width: 120px;
      }
    }


    .loglist {
      display: flex;
      justify-content: space-between;
      margin-bottom: 30px;

      .log_title {
        padding: 7px 10px;
      }
    }

    .listl {
      height: 350px;
      overflow: auto;

      /deep/ .el-input__inner {
        border: none;
        text-align: center
      }
    }

    .list {

      display: flex;
      text-align: center;
      color: #727272;
      line-height: 45px;
      border: 1px #EAEAEA solid;
      margin-top: -1px;

      .th {
        flex: 1;
        background: #F9F9F9;
        font-size: 14px;
      }

      .td {
        flex: 1;
        font-size: 14px;
        border-right: 1px #EAEAEA solid;
      }
    }

    .el-pagination {
      text-align: right;
      margin: 20px 0
    }

    .el-dialog__wrapper {
      z-index: 19999 !important;
    }

    .protag {
      /deep/ .el-tag {
        margin-right: 20px;
        margin-bottom: 20px;
      }
    }

    .addpro {


      /deep/ .el-steps {
        width: 100%;
        padding: 30px;
      }

      .step {
        margin-bottom: 20px;
        background: #FFFFFF;

        .redbor {
          .el-input__inner {
            border: 1px #EEF7FF solid;
          }
        }

        .tilte {
          background: #F9F9F9;
          padding-left: 30px;
          line-height: 45px;
          font-size: 14px;

          span {
            background: #B1E4FF;
            color: #FFFFFF;
            float: right;
            line-height: 15px;
            cursor: pointer;
            padding: 5px 0;
            display: block;
            width: 24px;
            text-align: center;
            margin-right: 20px;
            margin-top: 8px;
            border-radius: 14px;
          }
        }



        .con {
          background: #FFFFFF;
          padding: 35px;

          .flex {
            display: flex;
          }

          .ori {
            background: #FBFBFB;
            padding: 20px 10px;

            /deep/ .el-input {
              width: 300px;
            }

            /deep/ .el-form-item {
              margin-bottom: 20px;
            }

            /deep/ .el-form-item__label {
              width: 150px !important;
            }

            .wenhao2 {
              color: #999;
              font-size: 14px;
            }

            .no {
              display: flex;
              align-items: center;

              #drop {
                /deep/ .el-button--primary {
                  background: #409EFF
                }
              }

              .nonum {
                background: #409EFF;
                padding: 0px 10px;
                line-height: 35px;
                height: 35px;
                color: #FFFFFF;
                border-radius: 3px;
                display: block;
              }

              .el-button {}

              span {
                margin: 0 20px;
              }
            }

          }
        }

        .haochi {
          padding: 30px;

          /deep/ .el-select {
            margin-left: 20px;
          }
        }

        .btm0 {
          /deep/ .el-button {
            margin-left: 20px;
          }

          /deep/ .el-form-item {
            margin-bottom: 0;
          }
        }

        .label200 .el-form-item__label {
          width: 149px !important;
        }

        /deep/ .avatar-uploader .el-upload {
          border: 1px dashed #d9d9d9;
          border-radius: 6px;
          cursor: pointer;
          position: relative;
          overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
          border-color: #409EFF;
        }

        .avatar-uploader-icon {
          font-size: 28px;
          color: #8c939d;
          width: 178px;
          height: 178px;
          line-height: 178px;
          text-align: center;
        }

        .avatar {
          width: 178px;
          height: 178px;
          display: block;
        }

        .wenhao {
          background: #B1E4FF;
          color: #FFFFFF;
          line-height: 15px;
          cursor: pointer;
          padding: 5px 11px;
          margin-left: 20px;
          text-align: center;
          border-radius: 14px;
        }
      }

    }
  }
</style>
